
import { Route, Redirect,Switch} from 'react-router-dom'
import {Suspense} from "react"

let RouterView=({Routerlist})=>{
    let routerlsit=Routerlist.filter((item,index)=>{
        return !item.to
    })
    let redirect=Routerlist.filter((item,index)=>{
        return item.to
    })[0]

    return(
        <Suspense fallback={<div>...loading</div>}>
            <Switch>
                 {
                     routerlsit&&routerlsit.map((item,index)=>{
                         return <Route key={index} path={item.path} render={(routerprops)=>{
                             return <item.component {...routerprops} children={item.children}></item.component>
                         }}></Route>
                     })
                 }
                 {
                   redirect&&<Redirect from={redirect.from} to={redirect.to}></Redirect>
                 }
            </Switch>
        </Suspense>
    )
}

export default RouterView;